#ifndef QIHDISPATCHER_H
#define QIHDISPATCHER_H

#include "qihlogger.h"
#include "qihevent.h"

#include <QObject>
#include <QRunnable>

class QihDispatcher : public QObject, private QRunnable
{
	Q_OBJECT

public:
	QihDispatcher(QObject *parent);
	~QihDispatcher();

	// loggers management
	void addLogger(QihLogger* pLogger);
	void removeLogger(QihLogger* pLogger);
	void freeAllLoggers();
	QList<QihLogger*> Loggers() const { return _loggers; }

	// cache management
	quint32 cacheSize() const { return _cacheSize; }
	void setCacheSize(quint32 value) { _cacheSize = value; }

	// dispatch events
	void dispatch(QihEvent* pEvent);
	void flush();

public:
	// QRunnable interface
	void run() = 0;

private:
	QList<QihLogger*> _loggers;
	quint32 _cacheSize;
	QThread _flushThread;
};

#endif // QIHDISPATCHER_H
